#include "interface.h"

DECLARE_DRAWABLE_BEGIN(Polygon, Polygon)
  virtual void render() override {
    glBegin(GL_POLYGON);
    glColor3f(1.f, 1.f, 0.f);
    for (int i = 0; i < n; i++) {
      glVertex2f(R*cos(2 * pi / n*i), R*sin(2 * pi / n*i));
    }
    glEnd();
    glFlush();
  };
  virtual void processInput(sdl::event::Event &evt) override {
    if (evt.type != SDL_KEYDOWN) return;
    if (evt.key.keysym.sym == SDLK_KP_MINUS) {
      --n;
      if (n <= 3) n = 3;
    } else if (evt.key.keysym.sym == SDLK_KP_PLUS) {
      ++n;
    } else if (evt.key.keysym.sym == SDLK_UP) {
      R -= 0.1f;
      if (R <= 0.f) R = 0.1f;
    } else if (evt.key.keysym.sym == SDLK_DOWN) {
      R += 0.1f;
    }
  };
 protected:
  const GLfloat pi = 3.1415926f;
  int n = 3;//当n为3时为三角形；n为4时是四边形，n为5时为五边形。。。。。
  GLfloat R = 0.5f;//圆的半径
DECLARE_DRAWABLE_END(Polygon)